package com.ghsc.ghxc.jsb.ui.live.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.aliyun.aliinteraction.uikit.core.BaseComponent;
import com.aliyun.aliinteraction.uikit.core.ComponentHolder;
import com.aliyun.aliinteraction.uikit.core.IComponent;
import com.aliyun.auipusher.LiveContext;
import com.cn.appcore.event.RxBus;
import com.cn.appcore.event.RxBusBean;
import com.ghsc.ghxc.jsb.R;
import com.ghsc.ghxc.jsb.config.CustSignKey;

/**
 * @author 分享按钮
 * @version 2021/7/29
 */
public class LiveShareView extends FrameLayout implements ComponentHolder {

    private final Component component = new Component();

    public LiveShareView(@NonNull Context context) {
        this(context, null, 0);
    }

    public LiveShareView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public LiveShareView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View.inflate(context, R.layout.ilr_view_live_share, this);

        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                component.handleShareClick();
            }
        });
    }

    @Override
    public IComponent getComponent() {
        return component;
    }

    private class Component extends BaseComponent {


        String url ="";

        @Override
        public void onInit(LiveContext liveContext) {
            super.onInit(liveContext);
//            setVisibility(isOwner() ? GONE : VISIBLE);
            if (liveContext.getLiveModel().linkInfo!=null)
                url=liveContext.getLiveModel().linkInfo.liveCdnPullInfo.hlsUrl;
            else{
                url=liveContext.getLiveModel().pullUrlInfo.hlsUrl;
            }
        }

        private void handleShareClick() {
            RxBus.getDefault().post(
                   new RxBusBean(
                            CustSignKey.CUST_LIVE_SHARE_URL,
                            CustSignKey.CUST_LIVE_SHARE_URL,url)
            );
        }

        @Override
        public void onActivityDestroy() {

        }
    }
}
